package 自己写的

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"log"
	"net/http"
	"strconv"
	"sync"
	"time"
)

var (
	IDS       []string
	waitGroup sync.WaitGroup
)

func main() {
	fmt.Println("开始")
	start := time.Now()
	for i := 1; i < 49; i++ {
		waitGroup.Add(1)
		go BeiKeId(i)
	}
	waitGroup.Wait()
	fmt.Println(IDS)
	fmt.Println(len(IDS))
	fmt.Println(time.Now().Sub(start))
	fmt.Println("结束")
}

func BeiKeId(page int) {
	//发起请求
	resp, err := http.Get("https://cd.ke.com/xiaoqu/pengzhou/pg" + strconv.Itoa(page) + "/")
	if err != nil {
		fmt.Println("视频链接失效")
	}
	defer resp.Body.Close()
	doc, err := goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	doc.Find("ul.listContent > li").Each(func(i int, s *goquery.Selection) {
		id, _ := s.Attr("data-id")
		IDS = append(IDS, id)
	})
	waitGroup.Done()
}
